

import org.apache.spark.SparkConf;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class file {

    public static void main(String[] args) throws IOException {

        File file = new File("D:\\朴妮唛");

        f f = new f();
        String w= f.listSubFiles(file);
        String ss = w.replace("null", "");
        String[] s = ss.split("qq");


        for (String t:s){
        if (t!=null||t!=file.toString()) {
            boolean b = f.EncryptAndDecode(t);
            System.out.println(b);
            //listSubFiles(file);}
        }
    }}
    public static void listSubFiles(File dir) {
        //判断
        if (dir != null && dir.isDirectory()) {
            //获取dir里面内容
            File[] files = dir.listFiles();
            //files是否为空
            if (files != null) {
                //遍历
                for (File file : files) {
                    //递归调研
                    listSubFiles(file);
                }
            }
        }
        if (dir.isFile()){
            f f = new f();
            boolean b = f.EncryptAndDecode(f.toString());
        }
    }
    final int REVERSE_LENGTH = 100;

    boolean EncryptAndDecode(String strFile) {
        int len = REVERSE_LENGTH;
        try {
            File f = new File(strFile);
            RandomAccessFile raf = new RandomAccessFile(f, "rw");
            long totalLen = raf.length();

            if (totalLen < REVERSE_LENGTH)
                len = (int) totalLen;

            FileChannel channel = raf.getChannel();
            MappedByteBuffer buffer = channel.map(
                    FileChannel.MapMode.READ_WRITE, 0, REVERSE_LENGTH);
            byte tmp;
            for (int i = 0; i < len; ++i) {
                byte rawByte = buffer.get(i);
                tmp = (byte) (rawByte ^ i);
                buffer.put(i, tmp);
            }
            buffer.force();
            buffer.clear();
            channel.close();
            raf.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }



        }
